import requests
import parsel
import os

for i in range(1,3):
    headers = {

    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36'
    }
    url='http://www.bbsnet.com/doutu/page/{}'.format(i)

    reponse=requests.get(url,headers=headers,)
    reponse=requests.get(url,headers=headers)
    reponse.encoding=reponse.apparent_encoding
    html=reponse.text
    parse=parsel.Selector(html)
    img_url_list=parse.xpath('//div[@class="thumbnail"]/a/@href').extract()

    for img_url in img_url_list:
        response1=requests.get(img_url,headers=headers)
        response1.encoding=response1.apparent_encoding
        html1=response1.text
        parse1=parsel.Selector(html1)
        gif_url_list=parse1.xpath('//div[@class="context"]/div/p/img/@src').extract()
        print(gif_url_list)
        # for gif_url in gif_url_list:
        #     gif_data=requests.get(gif_url,headers=headers).content
        #
        #     with open('表情包','wb') as f:
        #         f.write(gif_data)


